<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
	<meta name = "format-detection" content="telephone = no" />
	<title>学生界面frame</title>
	<link rel="stylesheet" href="">
	<link rel="stylesheet" type="text/css" href="../../css/api.css">
	<link rel="stylesheet" type="text/css" href="../../css/mui.min.css">
	<link rel="stylesheet" type="text/css" href="../../css/base.css">
</head>
<style type="text/css">
body{
	-webkit-user-select:none; 
	        -moz-user-select:none; 
	        -ms-user-select:none; 
	        user-select:none;
	 }
	.bgSet{
        position: relative;
        height: 50px;
        color: black;
	}
	.mui-table-view-cell .mui-active{
		color: black;
		background-color: #f0f0f0;
	}
	.iconSet{
		width: 40px;
		height: 40px;
		position: absolute;
		left: 12%;
		top: 5px;
		border-radius: 20px;
	}
	.nameSet{
        width: 50%;
        height: 30px;
        line-height: 30px;
        vertical-align: middle;
        left: 25%;
        top: 10px;
        position: absolute;
        text-align: center;
        font-size: 16px;

	}
	.duigoutitle{
		width: 60px;
    	height: 20px;
    	text-align: left;
    	position: absolute;
    	left: 80%;
    	top: 15px;
    	font-size: 12px;
    	/* background-color: red; */
	}
    .duigou{
    	width: 20px;
    	height: 20px;
    	text-align: center;
    	position: absolute;
    	left: 80%;
    	top: 15px;
    	font-size: 12px;
    	/* background-color: red; */
    }

</style>
<body>
	<div class="main" id="main" hidden="hidden">
	    
	    <div class="mui-table-view-cell bgSet" onclick="clickCell(0.uid,status)">
	        
	        <img id="icon0" class="iconSet" src="../../image/icon_teacher_normal.png" alt="">
	        
	        <div id="name0" class="nameSet">张三</div>

	        <img id="states+uid" class="duigou" src="../../image/icon_unselecDuigou.png" alt="">
	    	
	    </div>
	    <div class="mui-table-view-cell bgSet" onclick="clickCell(0.uid,status)">
	        
	        <img id="icon0" class="iconSet" src="../../image/icon_teacher_normal.png" alt="">
	        
	        <div id="name0" class="nameSet">张三</div>

	        <span class="duigoutitle">已选</span>
	    	
	    </div>

	    <div class="mui-table-view-cell bgSet" onclick="clickCell(0.uid,status)">
	        
	        <img id="icon0" class="iconSet" src="../../image/icon_teacher_normal.png" alt="">
	        
	        <div id="name0" class="nameSet">张三</div>

	        <img id="states+uid" class="duigou" src="../../image/icon_duigou.png" alt="">
	    	
	    </div>

	</div>

	<div class="noSign"   id="noData"  hidden="hidden">
                <img src="../../image/icon_img.png" width="60%">
                <p class="font16 top_15 base_dark_grey" >
                    暂无数据
                </p>
            </div>
            <div class="loadFailure"  id="noNet" hidden="hidden">
                <img src="../../image/icon_img01.png" width="60%">
                <p class="" >
                    数据加载失败
                </p>
                <p>
                    请检查您的网络
                </p>
                <button type="button" class="mui-btn mui-btn-outlined" onclick="RefreshData()">
                    重新加载
                </button>
            </div>

</body>
<script type="text/javascript" src="../../script/mui.min.js"></script>
<script type="text/javascript" src="../../script/api.js"></script>
<script type="text/javascript" src="../../script/jquery.min.js"></script>
<script type="text/javascript" src="../../script/common.js"></script>
<script type="text/javascript" src="../../script/MD5.js"></script>
<script type="text/javascript" src="../../script/requestTool.js"></script>
<script type="text/javascript">

    var dataSource = [];   //总的数据源 
	
	var whiteGou = '';  
	var greenGou = '';
    
    var tmpClickArr = [];   //存放临时点击的uid
    var nameArr = [];   //存放选中的名字 集合
    var selectAllYesOrNo = 0;   //是否点了全选
    var currentShowGroup = 0;


	apiready = function(){
		whiteGou = '../../image/icon_unselecDuigou.png';
		greenGou = '../../image/icon_duigou.png';
		// alert(JSON.stringify($api.getStorage('tmpSelectedUid')));
		if ($api.getStorage('tmpSelectedUid').length > 0) {
			tmpClickArr = $api.getStorage('tmpSelectedUid');
		}

      loadData();



     api.addEventListener({
	        name: 'scrollTop'
	    }, function(ret, err) {

	    	$('html,body').animate({scrollTop: '0px'}, 100);

	    });

    

     api.addEventListener({
	        name: 'selectctStuNotification'
	    }, function(ret, err) {
            //tmpSelectedUid  tmpClickArr
            if (tmpClickArr.length > 0) {
            	$api.setStorage('tmpSelectedUid', tmpClickArr);
            	api.closeWin();
            	// alert(JSON.stringify(tmpClickArr));
                
                var nameArr = [];
                var uidArr = [];
            	for (var i = 0; i < dataSource.length; i++) {
            		for (var j = 0; j < tmpClickArr.length; j++) {
            			if (tmpClickArr[j] == dataSource[i].uid) {
                            nameArr.push(dataSource[i].showName);
                            uidArr.push(dataSource[i].uid);
            			}
            		}
            	}
            	// alert(JSON.stringify(nameArr));
            	// alert(JSON.stringify(uidArr));

            	api.sendEvent({
            	    name: 'refreshClassData',
            	    extra: {
            	        name: nameArr, 
            	        uid: uidArr,
            	    }
            	});
            	// $api.setStorage('selectStuUidAndName', nameArr);
            	// alert(JSON.stringify(nameArr));
            }else{
            	ShowToast("请选择学生");

            }

	    });
     

	}
	
	function loadData () {

        showProgress();
        var params = {
	        	uid : $api.getStorage('cfnetppuid'),
	        	jid : $api.getStorage('cfnetppjxid'),
	        	pid : api.pageParam.pid,
	        	vid : api.pageParam.vid,
	        	cid : api.pageParam.cid,
	   //      	jid:158,
				// uid:113184,
				// cid:234,
				// vid:6880155,
				// pid:3652,

	        };
	    // alert(JSON.stringify(params));
	    // alert(url_getSitenowScoreUser);
	    cfnetppPOST(url_getDiscussClasslist,params,true,function(data, status){
            api.hideProgress();
            if (status == 'success') {
				if (data.code == 200) {
					// alert(JSON.stringify(params));
					

                    $('#main').show();
                    $('#noData').hide();
					$('#noNet').hide();

					var get_data = data.data;
					// alert(JSON.stringify(get_data));
					// alert(get_data.length);


                    for (var j = 0; j < get_data.length; j++) {
					      var tmpdata = get_data[j];
						  var item = {};
						  item.uid = tmpdata.uid;
						  item.showName = selectName(tmpdata);
						  dataSource.push(item);

					}
					// alert(JSON.stringify(dataSource));

					initCellDataStu(get_data);
                    
                    
                    
				}else if(data.code == 108){  //无数据
					$('#noData').show();
					$('#main').hide();
					$('#noNet').hide();

				}else if(data.code == 101){   //参数错误
                    $('#main').hide();
	                $('#noData').hide();
					$('#noNet').show();
				}
			}else{
				$('#main').hide();
                $('#noData').hide();
				$('#noNet').show();
			}
		});

	}
	function selectName(user) {
		var showName = "";
		if (user.realname == null) {
            if (user.uname == null) {
            	if (user.email == null) {
            		if (user.phone == null) {
            			showName = "暂无姓名";
            		} else {
            			showName = user.phone;
            		}
            	} else {
            		showName = user.email;
            	}
            } else {
            	showName = user.uname;
            }
        }else{
        	showName = user.realname;
        } 
        return  showName;
	}
	function initCellDataStu(data) {

		var content = "";
		if (data.constructor == Array && data.length > 0){
			
			var myuid = $api.getStorage('cfnetppuid');
			
		    for (var j = 0; j < data.length; j++) {

        	var user = data[j];

        	//排除自己不能选择
    		if (user.uid != myuid) {
                var imgColor = "";


	            if (isContains(user.uid,tmpClickArr)) {
	            	imgColor = greenGou;
	            }else{
	            	imgColor = whiteGou;
	            }

	     //        content += '<div class="mui-table-view-cell bgSet" onclick="clickCell('+user.uid+','+user.status+')">'+
		        
		    //     '<img class="iconSet" src="../../image/icon_teacher_normal.png" alt="">'+
		        
		    //     '<div class="nameSet">'+user.rename+'</div>'+

		    //     '<img id="states'+user.uid+'" class="duigou" src="'+imgColor+'" alt="">'+
		    	
		    // '</div>';
	            var imgurl = user.picurl;
	            if (user.picurl == null) {
	            	imgurl = "../../image/icon_teacher_normal.png";
                    
	            }else{
                    imgurl = user.picurl;
	            }

	            var showName = selectName(user);
	            

	            if (user.status == 0) {
	                content += '<div class="mui-table-view-cell bgSet" onclick="clickCell('+user.uid+','+user.status+')">'+
		        
		        '<img class="iconSet" src="'+imgurl+'" alt="">'+
		        
		        '<div class="nameSet">'+showName+'</div>'+

		        '<img id="states'+user.uid+'" class="duigou" src="'+imgColor+'" alt="">'+
		    	
		    '</div>';
	            }else{
	                content += '<div class="mui-table-view-cell bgSet" onclick="clickCell('+user.uid+','+user.status+')">'+
		        
		        '<img class="iconSet" src="'+imgurl+'" alt="">'+
		        
		        '<div class="nameSet">'+showName+'</div>'+
		        '<span class="duigoutitle">已选</span>'+

		        // '<img id="states'+user.uid+'" class="duigou" src="'+imgColor+'" alt="">'+
		    	
		    '</div>';
	            }
    		}

			}

		}
        // alert(content);
		$('#main').html(content);
        $('#main').show();
		// alert(JSON.stringify(content));
		
	}
	

	function clickCell(uid,status) {
		// alert("uid:"+uid + "  " +"status:"+status);

        if (status == 1 || status == "1") {
            ShowToast("该学生已经被分在其他组中!");
        }else{
        	var imgId = "states"+uid;
        // alert("前"+JSON.stringify(tmpClickArr));
			if (isContains(uid,tmpClickArr)) {
				removeByValue(tmpClickArr,uid);
				// alert("移除了");

		        $('#'+imgId).attr('src', whiteGou);
			} else {
				tmpClickArr.push(uid);
				// alert("添加了");

		        $('#'+imgId).attr('src', greenGou);
			}
			// alert("后"+JSON.stringify(tmpClickArr));
	        $api.setStorage('tmpSelectedUid', tmpClickArr);
        }
    	

    	
    }

    function isContains(obj, arr) {
		if ($.inArray(obj, arr) != -1) {
			return true;
	}}

    function removeByValue(arr, val) {
		  for(var i=0; i<arr.length; i++) {
		    if(arr[i] == val) {
		      arr.splice(i, 1);
		      break;
		    }
		  }
		}

	


</script>
</html>
